package service;

import dao.*;
import entity.Flower;
import entity.Orders;

import java.util.List;

public class CustomerServiceImp implements CustomerService{
    @Override
    public List<Flower> checkFlower() {
        FlowerDAO fd = DBTestFactory.getInstance().getFlowerDAO();
        List<Flower> list = fd.checkFlower();
        return list;
    }

    @Override
    public List<Flower> checkFlowerByVariety(String variety) {
        FlowerDAO fd = DBTestFactory.getInstance().getFlowerDAO();
        List<Flower> list = fd.checkFlowerByVariety(variety);
        return list;
    }

    @Override   //flower---customer---flowerstore---orders
    public boolean buyFlower(int fid,int num,int cid,String consignee,String address,String cphone) {
        FlowerDAO fd = DBTestFactory.getInstance().getFlowerDAO();
        List<String> listflower = fd.buyFlower(fid,num);  //fid、variety、sum
        CustomerDAO cd = DBTestFactory.getInstance().getCustomerDAO();
        List<String> listcustomer = cd.buyFlower(cid);     //vip、name
        FlowerStoreDAO fsd = DBTestFactory.getInstance().getFlowerStoreDAO();
        boolean fsdbool = fsd.buyFlower(fid,num);       //商店数据更新是否成功
        OrdersDAO od = DBTestFactory.getInstance().getOrdersDAO();
        boolean odbool = od.buyFlower(fid,num,cid,consignee,address,cphone);         //订单信息是否插入成功
        if (!listflower.isEmpty() && !listcustomer.isEmpty() && fsdbool && odbool){
            return true;       //四个表都操作成功才能购买成功。
        }
        return false;
    }

    @Override
    public List<Orders> checkOrders() {
        OrdersDAO od = DBTestFactory.getInstance().getOrdersDAO();
        List<Orders> list = od.checkOrders();
        return list;
    }
}
